<template>
  <div>
    <van-swipe :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(image, index) in images" :key="index">
        <img :src="image" />
      </van-swipe-item>
    </van-swipe>
    <button class="area" @click="$router.push('/city')">
      {{ currentcity.label }}<van-icon name="arrow-down" size="8" />
    </button>
    <van-search
      v-model="value"
      disabled
      show-action
      placeholder="请输入小区或地址"
    >
      <template #action>
        <div @click="onSearch">
          <van-icon name="location-o" size="22px" color="#fff" />
        </div>
      </template>
    </van-search>
    <van-grid>
      <van-grid-item
        url="#"
        icon=""
        text="整租"
        to="/index"
      />
      <van-grid-item
        url="#"
        icon=""
        text="合租"
        to="/index"
      />
      <van-grid-item
        url="#"
        icon=""
        text="地图找房"
        to="/index"
      />
      <van-grid-item
        url="#"
        icon=""
        text="去出租"
        to="/index"
      />
    </van-grid>
    <div class="grid">
      <h3>租房小组<span class="right">更多</span></h3>
      <div class="grid-content">
        <div class="box" v-for="item in groups" :key="item.id">
          <div class="left">
            <img :src="'http://liufusong.top:8080' + item.imgSrc" alt="图片" />
          </div>
          <div class="right">
            <p>{{ item.title }}</p>
            <p>{{ item.desc }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getSwipers, getGroups } from '@/api/home'
// import { awaitgetcity } from '@/api/area'
export default {
  name: 'index-page',
  components: {},
  props: {},
  data() {
    return {
      images: [],
      groups: [],
      value: '',
      currentcity: JSON.parse(window.localStorage.getItem('currentcity')) || {
        label: '北京',
        value: 'AREA|88cff55c-aaa4-e2e0',
        pinyin: 'beijing',
        short: 'bj'
      }
    }
  },
  computed: {},
  watch: {},
  async created() {
    const res = await getSwipers()
    this.images = res.body.map(
      (item) => 'http://liufusong.top:8080' + item.imgSrc
    )
    // const res1 = await awaitgetcity()
    // const id = res1.body.find((item) => item.label === this.currentcity).value
    const res2 = await getGroups('北京')
    this.groups = res2.body
  },
  methods: {
    onSearch(val) {
      console.log(val)
      this.$router.push('/map')
    }
  }
}
</script>

<style scoped lang="less">
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
}
.van-swipe {
  height: 212px;
  width: 100%;
  img {
    height: 100%;
  }
}
.area {
  height: 34px;
  width: 64px;
  text-align: center;
  position: absolute;
  font-size: 14px;
  top: 26px;
  left: 20px;
  background-color: #fff;
  &::after {
    content: '';
    width: 2px;
    height: 17px;
    background-color: #ccc;
    position: absolute;
    transform: translate(9px, 2px);
  }
}
.van-search {
  width: 290px;
  height: 36px;
  position: absolute;
  top: 25px;
  left: 70px;
  background: rgba(0, 0, 0, 0);
}
/deep/.van-search__content {
  background-color: #fff;
}
/deep/.van-grid-item__content {
  height: 123px;
  img {
    height: 60px;
    width: 60px;
  }
}
.grid {
  background-color: #f6f5f6;
  width: 100%;
  h3 {
    height: 50px;
    font-size: 15px;
    color: #333;
    font-weight: normal;
    margin-left: 15px;
    line-height: 50px;
    .right {
      float: right;
      margin-right: 15px;
      font-size: 14px;
      color: #787d82;
    }
  }
  .grid-content {
    display: flex;
    justify-content: space-evenly;
    flex-wrap: wrap;
    .box {
      width: 173px;
      height: 60px;
      background: #fff;
      margin-bottom: 10px;
      .left {
        width: 50px;
        height: 50px;
        margin: 5px 10px;
        float: left;
        img {
          height: 100%;
        }
      }
      .right {
        float: left;
        margin: 10px 0px;
        p {
          font-size: 14px;
        }
      }
    }
  }
}
</style>
